package com.lysj.bhp.borrowing.service;

import com.lysj.bhp.borrowing.base.BorrowingContent;
import com.lysj.bhp.borrowing.domain.*;
import com.lysj.bhp.exchangerate.json.bcex.Data;
import com.lysj.bhp.util.random.FormatUtil;
import com.lysj.bhp.util.web.ParamUtil;
import com.lysj.bhp.util.web.Resp;
import com.lysj.bhp.wallet.domain.BhpcWallet;
import com.lysj.bhp.wallet.domain.BitCoinWallet;
import com.lysj.bhp.wallet.domain.EthereumWallet;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;


/**
 * @author drj
 * @date 2018/8/24 14:37
 * @Description:用户去还款业务层
 */
@Service
@Transactional
public class ReturnMoneyService extends BorrowingContent {
    /**
     * @author drj
     * @date 2018/8/24 14:37
     * @Description:正常还款
     */
    public Resp returnMoney(Long borrowingRecordId, Integer operate, String tradePassword) throws Exception {
        ServiceCharge serviceCharge = serviceChargeRepository.findOne(1L);
        BigDecimal serviceRate = serviceCharge.getServiceRate().divide(new BigDecimal(100));
        if (ParamUtil.isBlack(tradePassword)) {
            return new Resp(Resp.PARAM_ERROR, "请输入交易密码");
        }
        if (!ParamUtil.md5(tradePassword).equals(currentUser().getTradePassword())) {
            return new Resp(Resp.PARAM_ERROR, "交易密码错误");
        }
        if (ParamUtil.isBlack(borrowingRecordId)) {
            return new Resp(Resp.PARAM_ERROR, "请联系管理员");
        }
        //预留如果逾期，operate不能为2
        //当前还款记录
        BorrowingRecord borrowingRecord = borrowingRecordRepository.findOne(borrowingRecordId);
        //当前时间
        long currentTime = System.currentTimeMillis();
        Date actualRepaymentDate = new Date(currentTime);
        //
        List<BorrowingInstallment> creditFileBorrowingInstallments = borrowingInstallmentRepository.findByBorrowingRecordIdAndNperLessThanEqual(borrowingRecord.getBorrowingRecordId(), borrowingRecord.getProgress());
        //当前期
        BorrowingInstallment borrowingInstallment = borrowingInstallmentRepository.findByUserIdAndBorrowingRecordIdAndNper(borrowingRecord.getUserId(), borrowingRecord.getBorrowingRecordId(), borrowingRecord.getProgress() + 1);
        //应还金额
        BigDecimal totalReturnMoney = new BigDecimal(BigInteger.ZERO);
        BigDecimal currentReturnMoney = new BigDecimal(BigInteger.ZERO);
        //违约金
        BigDecimal penalSumMoney = new BigDecimal(BigInteger.ZERO);
        //borrowingInstallments保存类
        List<BorrowingInstallment> borrowingInstallments = new LinkedList<>();
        //信用档案
        CreditFile creditFile = creditFileRepository.findByUserIdAndWalletType(borrowingRecord.getUserId(), borrowingRecord.getBorrowingType());
        //提前还款月模式下违约金开关
        Boolean monthDefaultMoneySwitch = true;
        //defaultMoney 提取违约金
        BigDecimal defaultMoney = new BigDecimal(BigInteger.ZERO);
        //String BigDecimal Map集合
        Map<String,BigDecimal> map = new HashMap<>();
        //当前期
        if (operate == 1) {
            //本期需要还的钱
            currentReturnMoney = borrowingInstallment.getReturnMoney().add(borrowingInstallment.getReturnDividend()).add(borrowingInstallment.getDefaultMoney());
            //需要还的总额
            totalReturnMoney = totalReturnMoney.add(currentReturnMoney);
            if (borrowingRecord.getRefundWay() == 1 || borrowingRecord.getProgress() + 1 == borrowingRecord.getDeadline()) {
                borrowingRecord.setStatus(3);
            }
            //更新借贷分期记录
            updateBorrowingInstallment(borrowingRecord, borrowingInstallment, totalReturnMoney, actualRepaymentDate,BigDecimal.ZERO);
            //待还总额，已还总额更新
            updateCreditFile(creditFile, borrowingInstallment, totalReturnMoney);
            //添加需要更新的借贷信息
            borrowingInstallments.add(borrowingInstallment);
            creditFileBorrowingInstallments.add(borrowingInstallment);
        }
        //全部还款
        else {
            if (borrowingRecord.getRefundWay() == 1) {
                //到期还本付息 按天
                if (borrowingRecord.getRateType() == 1) {
                    if (borrowingInstallment.getBeginRepaymentDate().getTime() > new Date(currentTime).getTime()) {
                        currentReturnMoney = borrowingInstallment.getReturnMoney().add(borrowingInstallment.getReturnDividend().multiply(serviceRate)).setScale(18, BigDecimal.ROUND_HALF_UP);
                    } else if (borrowingInstallment.getBlacklistId() != 0) {
                        currentReturnMoney = borrowingInstallment.getReturnMoney().add(borrowingInstallment.getReturnDividend()).add(borrowingInstallment.getDefaultMoney());
                    } else {
                        map =  prepayment(borrowingInstallment.getBeginRepaymentDate(), FormatUtil.getDayStartDay(borrowingInstallment.getEndRepaymentDate()), new Date(currentTime), borrowingInstallment.getReturnMoney(), borrowingInstallment.getReturnDividend(), serviceRate);
                        currentReturnMoney = map.get("currentReturnMoney");
                        defaultMoney = map.get("default");
                    }
                    totalReturnMoney = totalReturnMoney.add(currentReturnMoney);
                }
                //到期还本付息 按月
                else {
                    //这边先切3个时间段出来。用if判断时间断。 3个判断添加
                    //每月应该还的利息
                    if (borrowingInstallment.getBlacklistId() != 0) {
                        totalReturnMoney = borrowingInstallment.getReturnMoney().add(borrowingInstallment.getReturnDividend()).add(borrowingInstallment.getDefaultMoney());
                    } else {
                        BigDecimal returnDividend = borrowingInstallment.getReturnDividend().divide(new BigDecimal(borrowingRecord.getDeadline()), 18, BigDecimal.ROUND_HALF_UP);
                        map = duePaymentsInterest(borrowingRecord, borrowingInstallment, currentTime, returnDividend, serviceRate);
                        penalSumMoney = map.get("sumMoney");
                        defaultMoney = map.get("defaultMoney");
                        totalReturnMoney = totalReturnMoney.add(penalSumMoney).add(borrowingInstallment.getReturnMoney()).setScale(18, BigDecimal.ROUND_HALF_UP);
                    }
                }
                //更新借贷分期记录
                updateBorrowingInstallment(borrowingRecord, borrowingInstallment, totalReturnMoney, actualRepaymentDate,defaultMoney);
                //待还总额，已还总额更新
                updateCreditFile(creditFile, borrowingInstallment, totalReturnMoney);
                borrowingInstallments.add(borrowingInstallment);
                creditFileBorrowingInstallments.add(borrowingInstallment);
                borrowingRecord.setStatus(3);
            } else {
                for (int i = borrowingRecord.getProgress() + 1; i <= borrowingRecord.getDeadline(); i++) {
                    borrowingInstallment = borrowingInstallmentRepository.findByUserIdAndBorrowingRecordIdAndNper(currentUser().getUserId(), borrowingRecord.getBorrowingRecordId(), i);
                    if (borrowingInstallment.getBlacklistId() != 0) {
                        currentReturnMoney = borrowingInstallment.getReturnMoney().add(borrowingInstallment.getReturnDividend()).add(borrowingInstallment.getDefaultMoney());
                    } else if (FormatUtil.isBetweenTime(new Date(currentTime), borrowingInstallment.getBeginRepaymentDate(), borrowingInstallment.getEndRepaymentDate())) {
                        //提前为日还款 本日照常算利息
                        if (borrowingRecord.getRateType() == 1) {
                            currentReturnMoney = borrowingInstallment.getReturnMoney().add(borrowingInstallment.getReturnDividend());
                        }
                        //提前为月还款 调用方法计算当月提前状态下金额
                        else {
                            map = advancedCurrent(borrowingInstallment,serviceRate);
                            currentReturnMoney = map.get("currentReturnMoney");
                            defaultMoney = map.get("defaultMoney");
                        }
                    } else {
                        //如果为天，则是后面剩余的所有违约金相加
                        if (borrowingRecord.getRateType() == 1) {
                            penalSumMoney = borrowingInstallment.getReturnDividend().multiply(serviceRate);

                        }
                        //如果为月，只取一个月的违约金
                        else {
                            if (monthDefaultMoneySwitch) {
                                penalSumMoney = borrowingInstallment.getReturnDividend().multiply(serviceRate);
                                monthDefaultMoneySwitch = false;
                            } else {
                                penalSumMoney = new BigDecimal(BigInteger.ZERO);
                            }
                        }
                        defaultMoney = penalSumMoney;
                        currentReturnMoney = borrowingInstallment.getReturnMoney().add(penalSumMoney);
                    }
                    //此还款提前金额
                    totalReturnMoney = totalReturnMoney.add(currentReturnMoney);
                    //更新借贷分期记录
                    updateBorrowingInstallment(borrowingRecord, borrowingInstallment, currentReturnMoney, actualRepaymentDate,defaultMoney);
                    defaultMoney = BigDecimal.ZERO;
                    //待还总额，已还总额更新
                    updateCreditFile(creditFile, borrowingInstallment, currentReturnMoney);
                    borrowingInstallments.add(borrowingInstallment);
                    creditFileBorrowingInstallments.add(borrowingInstallment);
                }
                borrowingRecord.setStatus(3);
            }
        }
        System.out.println(totalReturnMoney);
        //还款余额跟用户对应的可用资产进行判定
        String message = compareMoney(borrowingRecord.getBorrowingType(), totalReturnMoney, borrowingRecord.getUserId());
        if (!ParamUtil.isBlack(message)) {
            return new Resp(Resp.PARAM_ERROR, message);
        }
        borrowingInstallmentRepository.save(borrowingInstallments);
        borrowingRecordRepository.save(borrowingRecord);
        //该笔借款已结清
        if (borrowingRecord.getStatus() == 3) {
            //对应钱包资产修改
            borrowingRecordService.walletAvailBanceAndPledgeFreezeBalanceOperation(borrowingRecord.getMortgageType(), borrowingRecord.getUserId(), borrowingRecord.getMortgageMoney(), borrowingRecord.getMortgageMoney().multiply(new BigDecimal(-1)));
            //对应信用档案修改(多加了个还款记录参数)
            updateCreditFile(creditFile, creditFileBorrowingInstallments, borrowingRecord);
        }
        //流水信息表添加
        BorrowingAccount borrowingAccount = new BorrowingAccount();
        borrowingAccount.setUserId(borrowingRecord.getUserId());
        borrowingAccount.setPostAccountId(1L);
        borrowingAccount.setDealMoney(totalReturnMoney);
        borrowingAccount.setAccountType(2);//借款状态
        borrowingAccount.setWalletType(borrowingRecord.getBorrowingType());
        borrowingAccount.setCreateDate(new Date());
        borrowingAccountRepository.save(borrowingAccount);
        creditFileRepository.save(creditFile);
        return new Resp("还款成功");
    }

    /**
     * @author zwj
     * @date 2018-09-07 10:28
     * @@Description:资产判断
     */
    public String compareMoney(Integer type, BigDecimal returnMoney, Long userId) {
        String message = "";
        switch (type) {
            case 10:
                BitCoinWallet bitCoinWallet = bitcoinWalletRepository.findByUserId(userId);
                if (returnMoney.compareTo(bitCoinWallet.getAvailBalance()) >= 1) {
                    message = "可用资产不足,请进行充值";
                } else {
                    bitCoinWallet.setAvailBalance(bitCoinWallet.getAvailBalance().subtract(returnMoney));
                    bitCoinWallet.setBalance(bitCoinWallet.getBalance().subtract(returnMoney));
                    bitcoinWalletRepository.save(bitCoinWallet);
                }
                break;
            case 20:
                EthereumWallet ethereumWallet = ethereumWalletRepository.findByUserId(userId);
                if (returnMoney.compareTo(ethereumWallet.getAvailBalance()) >= 1) {
                    message = "可用资产不足,请进行充值";
                } else {
                    ethereumWallet.setAvailBalance(ethereumWallet.getAvailBalance().subtract(returnMoney));
                    ethereumWallet.setBalance(ethereumWallet.getBalance().subtract(returnMoney));
                    ethereumWalletRepository.save(ethereumWallet);
                }
                break;
            case 100:
                BhpcWallet bhpcWallet = bhpcWalletRepository.findByUserId(userId);
                if (returnMoney.compareTo(bhpcWallet.getAvailBalance()) >= 1) {
                    message = "可用资产不足,请进行充值";
                } else {
                    bhpcWallet.setAvailBalance(bhpcWallet.getAvailBalance().subtract(returnMoney));
                    bhpcWallet.setBalance(bhpcWallet.getBalance().subtract(returnMoney));
                    bhpcWalletRepository.save(bhpcWallet);
                }
                break;
        }
        return message;
    }

    /**
     * @author zwj
     * @date 2018-09-07 10:18
     * @@Description:借款明细更新
     */
    public void updateBorrowingInstallment(BorrowingRecord borrowingRecord, BorrowingInstallment borrowingInstallment, BigDecimal actualRepaymentMoney, Date actualRepaymentDate ,BigDecimal DefaultMoney) {
        //时间轴定义还款状态
        //状态：4.提前还款 当前时间在还款日的00：00：00 时间之前
        Integer repayStatus = 0;
        if (FormatUtil.getDayStartDay(borrowingInstallment.getEndRepaymentDate()).getTime() > actualRepaymentDate.getTime()) {
            repayStatus = 4;
            borrowingInstallment.setDefaultMoney(DefaultMoney);
        }
        //状态：5.准时还款 还款时间介于 00：00：00<= - <=17：00：00 时间之间
        else if (FormatUtil.getDayStartDay(borrowingInstallment.getEndRepaymentDate()).getTime() <= actualRepaymentDate.getTime() && actualRepaymentDate.getTime() <= FormatUtil.getDaySeventeDay(borrowingInstallment.getEndRepaymentDate()).getTime()) {
            repayStatus = 5;
        }
        //状态：3.迟还款 还款时间介于 17：00：00 < - <=23：59：59 时间之间
        else if (FormatUtil.getDaySeventeDay(borrowingInstallment.getEndRepaymentDate()).getTime() < actualRepaymentDate.getTime() && actualRepaymentDate.getTime() <= borrowingInstallment.getEndRepaymentDate().getTime()) {
            repayStatus = 3;
        }
        //状态：2.逾期还款
        else {
            repayStatus = 2;
        }
        borrowingRecord.setProgress(borrowingRecord.getProgress() + 1);
        borrowingInstallment.setRepayStatus(repayStatus);
        borrowingInstallment.setActualRepaymentDate(actualRepaymentDate);
        borrowingInstallment.setActualRepaymentMoney(actualRepaymentMoney);

    }

    /**
     * @author zwj
     * @date 2018-08-31 17:08
     * @@Description:更新用户信用档案
     */
    public void updateCreditFile(CreditFile creditFile, BorrowingInstallment borrowingInstallment, BigDecimal actualRepayMoney) {
        //已还总额
        creditFile.setRepaidBalance(creditFile.getRepaidBalance().add(actualRepayMoney));
        //待还总额
        creditFile.setReturnedBalance(creditFile.getReturnedBalance().subtract(borrowingInstallment.getReturnMoney().add(borrowingInstallment.getReturnDividend().add(borrowingInstallment.getDefaultMoney()))));
    }

    /**
     * @author zwj
     * @date 2018-08-31 17:08
     * @@Description:更新用户信用档案
     */
    public void updateCreditFile(CreditFile creditFile, List<BorrowingInstallment> borrowingInstallments, BorrowingRecord borrowingRecord) {
        //还款状态
        Integer finalRepayStatus = 10;
        //还款状态,1:逾期未还||2:逾期还款||3:迟还款||4:提前还款||5:准时还款
        Integer repayStatus = 0;
        //逾期还款金额
        BigDecimal overduePayOffBalance = new BigDecimal(BigInteger.ZERO);
        //提前还款金额
        BigDecimal advanceBalance = new BigDecimal(BigInteger.ZERO);
        //遍历判断添加各类记录
        for (BorrowingInstallment borrowingInstallment : borrowingInstallments) {
            //取出对应分期记录状态
            repayStatus = borrowingInstallment.getRepayStatus();
            //如果该笔提前还款则给提前还款金额叠加
            if (repayStatus == 4) {
                advanceBalance = advanceBalance.add(borrowingInstallment.getActualRepaymentMoney());
            }
            //如果该笔存在逾期还款 叠加逾期金额
            else if (repayStatus == 2) {
                overduePayOffBalance = overduePayOffBalance.add(borrowingInstallment.getActualRepaymentMoney());
            }
            //如果当前明细状态优先级小于明细状态优先级则将明细状态赋值给当前所记录的明细状态
            if (finalRepayStatus > repayStatus) {
                finalRepayStatus = repayStatus;
            }
        }
        //修改对应信用档案记录 对应添加各类笔数
        switch (finalRepayStatus) {
            case 2:
                //逾期 添加逾期还款金额 增加逾期还款笔数
                creditFile.setOverduePayOffAmount(creditFile.getOverduePayOffAmount() + 1);
                creditFile.setOverduePayOffBalance(creditFile.getOverduePayOffBalance().add(overduePayOffBalance));
                borrowingRecord.setRepayStatus(2);//逾期还款
                break;
            case 3:
                //迟还款 增加迟还款笔数
                creditFile.setLateAmount(creditFile.getLateAmount() + 1);
                borrowingRecord.setRepayStatus(3);//迟还款
                break;
            case 4:
                //提前还款 添提前笔数 增加提前还款金额
                creditFile.setAdvanceAmount(creditFile.getAdvanceAmount() + 1);
                creditFile.setAdvanceBalance(creditFile.getAdvanceBalance().add(advanceBalance));
                borrowingRecord.setRepayStatus(4);//提前还款
                break;
            case 5:
                //准时还款 增加准时还款笔数
                creditFile.setPunctualAmount(creditFile.getPunctualAmount() + 1);
                borrowingRecord.setRepayStatus(5);//准时还款
                break;
        }
        //还清次数+1
        creditFile.setPayOffAmount(creditFile.getPayOffAmount() + 1);
    }

    /**
     * @author zwj
     * @date 2018-08-31 17:47
     * @@Description: 提前当前月应还
     */
    public Map<String,BigDecimal> advancedCurrent(BorrowingInstallment borrowingInstallment,BigDecimal serviceRate) {
        Map<String,BigDecimal> result = new HashMap<>();
        //还款所需金额为:
        BigDecimal normalividene = new BigDecimal(BigInteger.ZERO);
        BigDecimal leftDividene = new BigDecimal(BigInteger.ZERO);
        //计算这期还款总天数
        long totalDays = FormatUtil.getDifferDays(borrowingInstallment.getBeginRepaymentDate(), borrowingInstallment.getEndRepaymentDate());
        //当前日
        long currentDays = FormatUtil.getDifferDays(borrowingInstallment.getBeginRepaymentDate(), new Date(System.currentTimeMillis()));
        //正常利息
        normalividene = borrowingInstallment.getReturnDividend().multiply(new BigDecimal(String.valueOf(currentDays))).divide(new BigDecimal(String.valueOf(totalDays)), 18, BigDecimal.ROUND_HALF_UP);
        //剩余利息(正常利息的30%)
        leftDividene = borrowingInstallment.getReturnDividend().multiply(new BigDecimal(String.valueOf(totalDays - currentDays))).divide(new BigDecimal(String.valueOf(totalDays)), 18, BigDecimal.ROUND_HALF_UP).multiply(serviceRate);
        //这一期的还款金额为
        BigDecimal currentReturnMoney = borrowingInstallment.getReturnMoney().add(normalividene).add(leftDividene);
        result.put("currentReturnMoney",currentReturnMoney);
        result.put("defaultMoney",leftDividene);
        return result;
    }

    /**
     * @author zwj
     * @date 2018-09-04 17:37
     * @@Description:提前还款还本付息获取利息加本金
     */
    public Map<String,BigDecimal> prepayment(Date beginDate, Date endDate, Date nowDate, BigDecimal returnMoney, BigDecimal returnDividend, BigDecimal serviceRate) {
        Map<String,BigDecimal> result = new HashMap<>();
        //违约金
        BigDecimal leftDividene = new BigDecimal(BigInteger.ZERO);
        //正常利息
        BigDecimal normalividene = new BigDecimal(BigInteger.ZERO);
        //贷款周期
        Long totalDays = FormatUtil.getDifferDays(beginDate, endDate);
        //正常利息日
        Long currentDays = FormatUtil.getDifferDays(beginDate, nowDate);
        //正常利息
        normalividene = returnDividend.multiply(new BigDecimal(String.valueOf(currentDays))).divide(new BigDecimal(String.valueOf(totalDays)), 18, BigDecimal.ROUND_HALF_UP);
        //剩余利息(正常利息的30%)
        leftDividene = returnDividend.subtract(normalividene).multiply(serviceRate).setScale(18, BigDecimal.ROUND_HALF_UP);
        //该期间该还利息
        BigDecimal currentReturnMoney = returnMoney.add(normalividene.add(leftDividene)).setScale(18, BigDecimal.ROUND_HALF_UP);
        result.put("currentReturnMoney",currentReturnMoney);
        result.put("defaultMoney",leftDividene);
        return result;
    }

    /**
     * @author zwj
     * @date 2018-09-04 17:37
     * @@Description:提前还款还本付息只获取利息
     */
    public Map<String,BigDecimal> prepaymentInterest(Date beginDate, Date endDate, Date nowDate, BigDecimal returnDividend, BigDecimal serviceRate) {
        Map<String,BigDecimal> result = new HashMap<>();
        //违约金
        BigDecimal leftDividene = new BigDecimal(BigInteger.ZERO);
        //正常利息
        BigDecimal normalividene = new BigDecimal(BigInteger.ZERO);
        //贷款周期
        Long totalDays = FormatUtil.getDifferDays(beginDate, endDate);
        //正常利息日
        Long currentDays = FormatUtil.getDifferDays(beginDate, nowDate);
        //正常利息
        normalividene = returnDividend.multiply(new BigDecimal(String.valueOf(currentDays))).divide(new BigDecimal(String.valueOf(totalDays)), 18, BigDecimal.ROUND_HALF_UP);
        //剩余利息(正常利息的30%)
        leftDividene = returnDividend.subtract(normalividene).multiply(serviceRate).setScale(18, BigDecimal.ROUND_HALF_UP);
        //该期间该还利息
        BigDecimal currentReturnMoney = normalividene.add(leftDividene).setScale(18, BigDecimal.ROUND_HALF_UP);
        result.put("currentReturnMoney",currentReturnMoney);
        result.put("defaultMoney",leftDividene);
        return result;
    }

    /**
     * @author zwj
     * @date 2018-09-05 17:56
     * @@Description:月到期还本付息产生利息
     */
    public Map<String,BigDecimal> duePaymentsInterest(BorrowingRecord borrowingRecord, BorrowingInstallment borrowingInstallment, Long currentTime, BigDecimal returnDividend, BigDecimal serviceRate) throws Exception {
        Map<String,BigDecimal> result = new HashMap<>();
        BigDecimal defaultMoney = new BigDecimal(BigInteger.ZERO);
        //违约金
        BigDecimal penalSumMoney = new BigDecimal(BigInteger.ZERO);
        BigDecimal monthPenalSumMoney = new BigDecimal(BigInteger.ZERO);
        BigDecimal normalSumMoney = new BigDecimal(BigInteger.ZERO);
        for (int i = 1; borrowingRecord.getDeadline() >= i; i++) {
            Date beginDate = FormatUtil.getDayStartDay(FormatUtil.getNaturalMonth(borrowingInstallment.getBeginRepaymentDate(), i - 1));
            Date endDate = FormatUtil.getEndYesterday(FormatUtil.getNaturalMonth(borrowingInstallment.getBeginRepaymentDate(), i));
            //当前时间在endDate时间之后
            if (endDate.getTime() < new Date(currentTime).getTime()) {
                normalSumMoney = normalSumMoney.add(returnDividend);
            }
            //有期数介于本日时间之中
            else if (FormatUtil.isBetweenTime(new Date(currentTime), beginDate, endDate)) {
                Map<String,BigDecimal> map = prepaymentInterest(beginDate, endDate, new Date(currentTime), returnDividend, serviceRate);
                penalSumMoney = penalSumMoney.add(map.get("currentReturnMoney"));
                defaultMoney = map.get("defaultMoney");
            }
            //有期数再当前时间之前
            else if(beginDate.getTime()>new Date(currentTime).getTime()){
                monthPenalSumMoney = returnDividend.multiply(serviceRate);
            }
        }
        result.put("sumMoney",penalSumMoney.add(monthPenalSumMoney).add(normalSumMoney).setScale(18, BigDecimal.ROUND_HALF_UP));
        result.put("defaultMoney",defaultMoney);
        return result;
    }


}
